﻿Imports System.Diagnostics

Public Class Functional
#Region "Tortoise SVN"
    Public Sub tortoise_diff(ByVal filepath As String, ByVal rev1 As Integer, ByVal rev2 As Integer)
        '' TortoiseProc.exe /command:diff /path:""" & filepath & """ /startrev:" & rev1.ToString & " /endrev:" & rev2.ToString & " /closeonend:0
        Dim p As Process = New Process
        p.StartInfo.FileName = "TortoiseProc.exe"
        p.StartInfo.Arguments = "/command:diff /path:""" & filepath & """ /startrev:" & rev1.ToString & " /endrev:" & rev2.ToString & " /closeonend:0"
        p.StartInfo.UseShellExecute = False
        p.Start()
        p.Close()
    End Sub ' TortoiseProc.exe /command:diff /path:PATH /startrev:REV1 /endrev:REV2 /closeonend:0

    Public Sub tortoise_export()

    End Sub ' TortoiseProc.exe /notempfile /command:dropexport /droptarget:svnpath /path:buildpath
#End Region

#Region "Subversion"
    Public Function svn_diff(ByVal rev1 As Integer, ByVal rev2 As Integer, ByVal file As String) As String
        Dim p As Process = New Process
        p.StartInfo.FileName = "cmd.exe"
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.Start()
        Dim sw As IO.StreamWriter = p.StandardInput
        sw.WriteLine("diff -r " & rev1.ToString & ":" & rev2.ToString & " " & file)
        sw.Close()
        Dim output As String = p.StandardOutput.ReadToEnd
        p.WaitForExit()
        p.Close()
        Return output
    End Function ' svn diff -r REV1:REV2 path
    Public Sub svn_export()

    End Sub ' svn export -r REV URLsvnpath build path
#End Region

#Region "Windows"
    Public Function MoveFile(ByVal File As String, ByVal From As String, ByVal Too As String) As Boolean
        If System.IO.File.Exists(From & File) = True Then
            Try
                System.IO.Directory.Move(From & File, Too & File)
            Catch ex As IO.IOException
                MsgBox("Unable to move " & File.ToString & " to " & Too.ToString)
                Return False
            End Try
            Return True
        End If
    End Function
    Public Function MoveDirectory(ByVal From As String, ByVal Too As String) As Boolean
        If System.IO.Directory.Exists(From) = True Then
            Try
                System.IO.Directory.Move(From, Too)
            Catch ex As IO.IOException
                MsgBox("Unable to move directory " & From.ToString & " to " & Too.ToString)
                Return False
            End Try
            Return True
        End If
    End Function
    Public Function CopyFile(ByVal File As String, ByVal From As String, ByVal Too As String) As Boolean
        If System.IO.File.Exists(From & File) = False Then
            Try
                System.IO.File.Copy(From & File, Too & File)
            Catch ex As IO.IOException
                MsgBox("Unable to copy " & File.ToString & " to " & Too.ToString)
                Return False
            End Try
            Return True
        End If
    End Function
    Public Function CopyDirectory(ByVal From As String, ByVal Too As String) As Boolean
        If System.IO.Directory.Exists(From) = False Then
            Try
                My.Computer.FileSystem.CopyDirectory(From, Too)
            Catch ex As Exception
                MsgBox("Unable to copy directory " & From.ToString & " to " & Too.ToString)
                Return False
            End Try
            Return True
        End If
    End Function
    Public Function CreateFile(ByVal File As String, ByVal path As String) As Boolean
        If System.IO.File.Exists(path & File) = True Then
            Try
                System.IO.File.Create(path & File)
            Catch ex As IO.IOException
                MsgBox("Unable to create file here:" & path.ToString & File.ToString)
                Return False
            End Try
            Return True
        End If
    End Function
    Public Function CreateDirectory(ByVal path As String) As Boolean
        If System.IO.Directory.Exists(path) = True Then
            Try
                System.IO.Directory.CreateDirectory(path)
            Catch ex As IO.IOException
                MsgBox("Unable to create directory here:" & path.ToString)
                Return False
            End Try
            Return True
        End If
    End Function
    Public Function Commandline(ByVal command As String) As String
        Dim p As Process = New Process
        p.StartInfo.FileName = "cmd.exe"
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.Start()
        Dim sw As IO.StreamWriter = p.StandardInput
        sw.WriteLine(command)
        sw.Close()
        Dim output As String = p.StandardOutput.ReadToEnd
        p.WaitForExit()
        p.Close()
        Return output
    End Function ' Use cmd.exe
    Public Function ErrorCheck(ByVal path As String, ByVal err As String) As Boolean
        Dim sr As New IO.StreamReader(path)
        Dim text As String = sr.ReadToEnd
        If text.Contains(err) = True Then
            Return True
        Else
            Return False
        End If
    End Function
#End Region
End Class
